﻿/*-----------------------------------------------
// File: GameConfig.cs
// Description: 客户端的一些参数设置
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;

public class GameConfig : MonoBehaviour
{

    public int platform = 1;//1为PC登录，2为SDK登录

    private string appLocalVersion = "1.1.0.20";
    public string resPackageVersion = "62";
    //private int dataLocalVersion = 0;

    
    [SerializeField]
    private bool isFirstBattleEnter;
    private string channelId;
    private string channelName;
    private string shopId;
    public bool dataChange = false;
    public bool isSwitch = false;
    public string AppVersion
    {
        get
        {
            if (GameConfig.Instance.platform == 1)
            {
                return appLocalVersion;
            }
            else
            {
				#if UNITY_ANDROID
                if (string.IsNullOrEmpty(supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("APP_VERSION")))
                {
                    return appLocalVersion;
                }
                else
                {
                    return supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("APP_VERSION");
                }
				#endif
				#if UNITY_IOS
					return appLocalVersion;
				#endif
            }
            
        }
        
    }
    public string PreAppVersion
    {
        get
        {
            return PlayerPrefs.GetString("preVersion","");
        }
        set
        {
            PlayerPrefs.SetString("preVersion", value);
        }

    }
    /// <summary>
    /// 后面再加，资源版本号
    /// </summary>
    public string ResVersion
    {
        get 
        {
            return PlayerPrefs.GetString("resVersion","0");
            //int irv = int.Parse(rv);
            //return Mathf.Max(irv,int.Parse(resLocalVersion)).ToString();
        }
        set
        {
            PlayerPrefs.SetString("resVersion", value);
        }
    }

    public string serverAppVersion;
    public string serverResVersion;
    public string announceUrl = null;
    public bool userLogin = false;
    public string resUrl = null;
    public int programMethod;
    public ResourceUpdateMethod resMethod;
    public string appUrl;
    public bool isaudit=false;//是否审核模式
    public bool needActivation = false;//需要激活码
    public string activationUrl = "";//获取激活码的网址
#if UNITY_EDITOR
    private bool isFull = true;

#elif UNITY_IPHONE
	private bool isFull = true;
#elif GDZJ
    private bool isFull = true;
#else
    private bool isFull = false;
#endif
    public bool IsAssetFull
    {
        get
        {
            if(isFull)
            {
                return true;
            }
            return PlayerPrefs.GetInt("full", 0) == 1;
        }
        set
        {
            PlayerPrefs.SetInt("full", value ? 1 : 0);
        }
    }

    public bool IsDownloadOver
    {
        get
        {
            return PlayerPrefs.GetInt("downover", 0) == 1;
        }
        set
        {
            PlayerPrefs.SetInt("downover", value ? 1 : 0);
        }
    }

    public string GetShopId 
    {
        get 
        {
            if (GameConfig.Instance.platform == 1)
            {
                return "pc";
            }
            else
            {
#if UNITY_ANDROID
                if (string.IsNullOrEmpty(supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("SHOP_ID")))
                {
                    return "common";
                }
                else
                {
                    return supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("SHOP_ID");
                }
#endif
#if UNITY_IOS
				return "ios360";
#endif
            }
           
        }
    }
    public string GetDeviceID
    {
        get
        {
#if UNITY_ANDROID || UNITY_EDITOR
            return SystemInfo.deviceUniqueIdentifier;
#endif
#if UNITY_IOS
            return supersdkUnity.SuperSDKPlugin.call("ios_idfa_plugin");
#endif
        }
    }
    public string GetChannelId 
    {
        
        get 
        {
            if (GameConfig.Instance.platform == 1)
            {
                
#if UNITY_ANDROID
                return ChannelId.AND_TEST;
#elif UNITY_IOS
                return ChannelId.IOS_TEST;
#endif
                //return ChannelId.PC;
            }
            else
            {
#if UNITY_ANDROID
                if (string.IsNullOrEmpty(supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("CHANNEL_ID")))
                {
                    return ChannelId.PC;
                }
                else
                {
                    return supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("CHANNEL_ID");
                }
#endif
#if UNITY_IOS
                return ChannelId.ios360;
#endif
            }
           
            
        }
    }

    public string GetChannelName 
    {
        get 
        {
            if (GameConfig.Instance.platform == 1)
            {
#if UNITY_ANDROID
                return ChannelId.WDJ;
#elif UNITY_IOS
                return ChannelId.IOS_TEST;
#endif
                //return ChannelId.PC;
                //return ServerConfig.GetChannelName(ChannelIDConfig.PC);//
                //return "QihuTest";//给日本人看的
            }
            else
            {
#if UNITY_ANDROID
                if (string.IsNullOrEmpty(supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("CHANNEL_NAME")))
                {
                    return "pc";
                }
                else
                {
                    return supersdkUnity.SuperSDKUnity3D.getUserDefinedValue("CHANNEL_NAME");
                }
#elif UNITY_IOS
				return ChannelId.ios360;
#endif
            }
           
           
        }
    }
    public bool IsFirstBattleEnter
    {
        get
        {
            
#if UNITY_EDITOR
            return isFirstBattleEnter;
#else
            var v = PlayerPrefs.GetInt("FirstGameEnter", 1);
            return v == 1 ? true : false;
#endif
        }

        set
        {
            isFirstBattleEnter = value;
            PlayerPrefs.SetInt("FirstGameEnter", value ? 1 : 0);
        }
    }

#region Singlton
    private static GameConfig instance = null;
    void Awake()
    {
        instance = this;
        DontDestroyOnLoad(gameObject);
    }
    public static GameConfig Instance
    {
        get
        {
            return instance;
        }
    }

#endregion
}